package cm.tl.pms.util;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

/**
 * @author w7h1te_ywq
 * @version 1.0.0
 * @date 2024-10-23 10:35
 */
public class SeasonUtil {


    public static String getCurrentQuarter() {
        LocalDate currentDate = LocalDate.now();
        int year = currentDate.getYear();
        int month = currentDate.getMonthValue();
        int quarter = (month - 1) / 3 + 1; // 计算季度
        return year + "-" + quarter;
    }


    public static String convertToQuarter(String dateStr) {
        LocalDate date = LocalDate.parse(dateStr, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
        int year = date.getYear();
        int month = date.getMonthValue();
        int quarter = (month - 1) / 3 + 1;
        return year + "-" + quarter;
    }

    public static String convertToQuarter(LocalDate date) {
        int year = date.getYear();
        int month = date.getMonthValue();
        int quarter = (month - 1) / 3 + 1;
        return year + "-" + quarter;
    }

    public static void main(String[] args) {
        System.out.println(convertToQuarter("2024-03-01"));
        System.out.println(convertToQuarter("2024-04-01"));
    }

}
